package com.hefu.virtuallife.ui.purchase;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.hefu.virtuallife.R;
import com.hefu.virtuallife.baseui.BaseActivity;
import com.hefu.virtuallife.baseui.BaseFragment;
import com.hefu.virtuallife.ui.purchase.adapter.PointUseViewPagerAdapter;
import com.hefu.virtuallife.ui.purchase.adapter.RecordPointAdapter;
import com.hefu.virtuallife.ui.purchase.bean.RecordPointBean;
import com.hefu.virtuallife.ui.purchase.fragment.MyGetPointFragment;
import com.hefu.virtuallife.ui.purchase.fragment.MyUsedFragment;
import com.hefu.virtuallife.widget.ToolListView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * creat_user: zhengzaihong
 * email:1096877329@qq.com
 * creat_date: 2018/8/13
 * creat_time: 18:29
 * describe: 我的积分
 **/
public class MyPointActivity extends BaseActivity implements OnRefreshLoadMoreListener {
    @BindView(R.id.iv_back)
    ImageButton ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_right)
    ImageButton ivRight;
    @BindView(R.id.view_pager)
    ViewPager viewpager;
    @BindView(R.id.scrollView)
    ScrollView scrollView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;

    @BindView(R.id.lv_history_record)
    ToolListView lvHistoryRecord;
    @BindView(R.id.tv_status)
    TextView tvStatus;
    @BindView(R.id.iv_select)
    ImageView ivSelect;
    @BindView(R.id.iv_unselect)
    ImageView ivUnselect;

    private RecordPointAdapter recordpointadapter;

    private PointUseViewPagerAdapter pagerAdapter;

    private List<BaseFragment> baseFragments = new ArrayList<>();


    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_my_point;
    }


    @Override
    protected void initWidget() {
        super.initWidget();

        ivBack.setVisibility(View.VISIBLE);
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText("我的积分");
        ivBack.setOnClickListener(v -> finish());
    }

    @Override
    protected void initData() {
        super.initData();


        scrollView.smoothScrollTo(0, 0);

        BaseFragment getpoint = new MyGetPointFragment();
        baseFragments.add(getpoint);

        BaseFragment usedpoint = new MyUsedFragment();
        baseFragments.add(usedpoint);

        pagerAdapter = new PointUseViewPagerAdapter(getSupportFragmentManager(), baseFragments);
        viewpager.setOffscreenPageLimit(baseFragments.size());
        viewpager.setAdapter(pagerAdapter);


        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    ivSelect.setBackgroundResource(R.drawable.select_dot_blue);
                    ivUnselect.setBackgroundResource(R.drawable.un_select_dot_blue);
                    tvStatus.setText("已获得");
                } else {
                    ivSelect.setBackgroundResource(R.drawable.un_select_dot_blue);
                    ivUnselect.setBackgroundResource(R.drawable.select_dot_blue);
                    tvStatus.setText("已使用");
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });


        refreshLayout.setOnLoadMoreListener(this);
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.autoRefresh();
        refreshLayout.setEnableLoadMore(false);

        List<RecordPointBean> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            RecordPointBean bean = new RecordPointBean();
            list.add(bean);
        }
        recordpointadapter = new RecordPointAdapter(mContext, list);
        lvHistoryRecord.setAdapter(recordpointadapter);


    }

    @Override
    public void onLoadMore(RefreshLayout refreshLayout) {

    }

    @Override
    public void onRefresh(RefreshLayout refreshLayout) {


        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
